/*************************************************
Author: will
Date: 9/19/2012
Description:
Notes: 
*************************************************/

#ifndef __cmduserinfo_h__
#define __cmduserinfo_h__

#include "../maindef.h"
#include "CTKeyValue.h"
#include "commclass.h"
#include "PBMsgHead.pb.h"
#include "MsgLogin.pb.h"
#include "MsgUserInfo.pb.h"
#include "MsgStorage.pb.h"
#include "MsgUserGuide.pb.h"

class CMainCtrl;
class CCmdLogin : public CTAsyncCmd
{
public:
    CCmdLogin()
    {
        uiGID = 0;
        bIsNewbie = false;
        bIsTencentLogin = false;
        bIsCheckLogin = false;
        bIsCheckInvited = false;
        bHasInvitedInfo = false;
        bIs32WanLogin = false;
        bIsYD10086Login = false;
        bIsHttpCreateUser = false;
        bIsCheckInitInfo = false;
    }

    virtual int Do(void* pData);
    virtual int AnsClients(int iRet);
    virtual int CallBack(int iRet);
    virtual int LogicDo(int iRet);

    CMainCtrl* pstMainCtrl;
    PBMsgHead  stMsgHead;
    CEnpNetHead stEnpHead;

    MsgReqLogin stReq;
    MsgAnsLogin stAns;
    unsigned int uiGID;

    CTSizeString<USER_TOKEN_LEN> szUserToken;
    CTSizeString<ROLENAME_LEN> szRoleName;
    bool bIsNewbie;     //用户是否注册过
    bool bIsTencentLogin; //是否从平台登录
    bool bIsCheckLogin; //是否已经检查登录
    bool bIsCheckInvited; //是否已经检查被邀请关系
    bool bHasInvitedInfo; //是否已经校验过的被邀请关系
    bool bIsFromMarket;  //是否从任务集市过来的
    bool bIsCheckFromMarket;   //是否已经判断集市登陆
    unsigned int uiMarketTaskId;

    CTLib::CTKeyValue  stTencentApiKeyValue;  //腾讯平台通用参数

    bool bIs32WanLogin; //是否从32wan登录
    bool bIsYD10086Login; //是否从移动10086登录

    bool bIsHttpCreateUser;
    bool bIsCheckInitInfo;

}; 

class CCmdGetUserInfo : public CTAsyncCmd
{
public:
    CCmdGetUserInfo();

    virtual int Do(void* pData);
    virtual int AnsClients(int iRet);
    virtual int LogicDo(int iRet);

    CMainCtrl* pstMainCtrl;
    PBMsgHead  stMsgHead;
    CEnpNetHead stEnpHead;

    MsgReqGetUserInfo stReq;
    MsgAnsGetUserInfo stAns;
    unsigned int uiGID;
    bool bHasGetTencentUserInfo;        //是否已经从平台获取用户信息
    bool bHasGetYellowInfo; //是否已经获取黄钻信息
    bool bIsYellow;
    bool bIsBlue;
};

class CCmdLogout : public CTAsyncCmd
{
public:
    CCmdLogout()
        :_uiGID(0)
    {

    }

    virtual int Do(void* pData);
    virtual int LogicDo(int iRet);

    CMainCtrl* pstMainCtrl;

    CEnpNetHead stEnpHead;
    unsigned int    _uiGID;

    unsigned int _uiNowMapID;
};

class CCmdInitUserInfo : public CTAsyncCmd
{
public:
    CCmdInitUserInfo() : _bIsHttpInit(false), _bIsTencentLogin(false), _bHasCheckSenWord(false), _iRet(-1) {}

    virtual int Do(void* pData);
    virtual int AnsClients(int iRet);
    virtual int LogicDo(int iRet);

    CMainCtrl* pstMainCtrl;
    PBMsgHead  stMsgHead;
    CEnpNetHead stEnpHead;

    MsgReqInitUserInfo stReq;
    unsigned int _uiGID;
    bool _bIsHttpInit;  //是否由网页创建初始化
    bool _bIsTencentLogin;  //是否由网页创建初始化
    bool _bHasCheckSenWord; //是否已经检查屏蔽字

    int _iRet;

public:
    static int CheckNewRoleName(CTSizeString<ROLENAME_LEN>& szRoleName);
};

class CCmdGetUserStorageInfo : public CTAsyncCmd
{
public:
	enum REQ_STORAGE_KEY
	{
		 REQ_BAG_INFO = 1,            //请求背包信息
		 REQ_WAREHOUSE_INFO = 2,	  //请求仓库信息
	};
	
    virtual int Do(void* pData);
    virtual int AnsClients(int iRet);
    virtual int LogicDo(int iRet);

    CMainCtrl* pstMainCtrl;
    PBMsgHead  stMsgHead;
    CEnpNetHead stEnpHead;

    MsgReqUserStorageInfo stReq;
    MsgAnsUserStorageInfo stAns;
    unsigned int _uiGID;
};

class CCmdCheckRolename : public CTAsyncCmd
{
public:
    virtual int Do(void* pData);
    virtual int AnsClients(int iRet);

    CMainCtrl* pstMainCtrl;
    PBMsgHead  stMsgHead;
    CEnpNetHead stEnpHead;

    MsgReqCheckRolename stReq;
    MsgAnsCheckRolename stAns;

    unsigned int uiGID;
}; 

class CCmdUserGuideInfo : public CTAsyncCmd
{
public:
    virtual int Do(void* pData);
    virtual int LogicDo(int iRet);
    virtual int AnsClients(int iRet);

    CMainCtrl* pstMainCtrl;
    PBMsgHead  stMsgHead;
    CEnpNetHead stEnpHead;

    MsgReqUserGuide stReq;
    MsgAnsUserGuide stAns;

    unsigned int uiGID;
}; 

class CUserTokenAndGID
{
public:
    unsigned int uiGID;
    CTSizeString<USER_TOKEN_LEN> szUserToken;
};

class CCmdGetMultiTencentInfo : public CTAsyncCmd
{
public:
    virtual int Do(void* pData);
    virtual int LogicDo(int iRet);
    virtual int AnsClients(int iRet);

    CMainCtrl* pstMainCtrl;
    PBMsgHead  stMsgHead;
    CEnpNetHead stEnpHead;

    MsgReqGetMultiTencentInfo stReq;
    MsgAnsGetMultiTencentInfo stAns;

    unsigned int uiGID;
    bool bHasSendMsg;

    CTLib::CTArray<CUserTokenAndGID, 100> _astUserTokenAndGID;

    unsigned int GetGidByToken(CTSizeString<USER_TOKEN_LEN>& szUserToken)
    {
        for (int i = 0; i < _astUserTokenAndGID.Size(); ++i)
        {
            if (szUserToken == _astUserTokenAndGID[i].szUserToken)
            {
                return _astUserTokenAndGID[i].uiGID;
            }
        }

        return 0;
    }
}; 


#endif // __cmduserinfo_h__


